var util = {
    modifyDes: function($elem) {
        des = $elem.text();
        des = des.length <= 35? des: des.slice(0,34) + "...";
        $elem.text(des);
    },
    getMoreAuthors: function() {
        url = $('.change').attr('href') + "?get=0";
        $.ajax({
            type: "get",
            url: url,
            cache: false,
            dataType : "xml",
            beforeSend: function() {
                $(".loading").show();
            },
            complete: function() {
                $(".loading").hide();
            },
            success: function(xml) {
                var ul = $(xml).children("root").children("ul").text();
                var href = $(xml).children("root").children("href").text();
                var current  = $(xml).children("root").children("current").text();
                var next = $(xml).children("root").children("next").text();
                if (current !== next) {
                    $(".authors ul").append(ul);
                    $(".change").attr('href',href);
                    $(".author_des").each(function() {
                        util.modifyDes($(this));
                    });
                } else {
                    $(".change span").text("加载完啦！！");
                    $(window).unbind("scroll");
                }
            }
        });
    }
};
$(document).ready(function() {
    //截短帐号的简介
    $(".author_des").each(function() {
        util.modifyDes($(this));
    });

    $(".author_page .avatar").hover(function() {
        $(this).parent().next().slideDown(400);
        return false;
    }, function() {
        $(this).parent().next().slideUp(300);
    });

    $(window).scroll(function() {
        //判断是否滚动到底部
        if (  ($(this).height() + $(this).scrollTop()) >= ($("body").height() - 50) ) {
            util.getMoreAuthors();
        }
    });
});
